Imports System.Data
Imports System.Xml
Imports System.Data.SqlClient
Imports AppsUtility.EncDec
Imports System.Configuration

Module MainModule
    Public CurrentDB As String = ""
    Public PastYearDB As String = ""
    Public PPastYearDB As String = ""
    Public LocationTypeID As String = "WH"
    Public dgProductSelectedID As Integer
    Public dgDelID As Integer
    Public dgAdjustmentSelectedID As Integer
    Public dgGroupSelectedID As Integer
    Public dgDocSelectedID As Integer
    Public dgLocationSelectedID As Integer
    Public LoginYear As String
    Public dgTrxNumber As String
    Public CompanyID As Integer
    Public CompanyTitle As String
    Public UserID As Integer
    Public UserName As String
    Public dspo As DataSet = New DataSet()
    Public rtlmsg As String
    Public UserGroupID As Integer
    Public CashierID As Integer
    Public ArCompanyID As Integer = 4
    Public Sort1 As Integer = 0
    Public Sort2 As Integer = 0
    Public Sort3 As Integer = 0
    Public Sort4 As Integer = 0
    Public Sort5 As Integer = 0
    Public EditEventID As Integer = 0
    Public EditProfileID As Integer = 0
    Public EditCusID As Integer = 0
    Public EditSupID As Integer = 0
    Public EditGlMain As String
    Public EditGlSub As String
    Public EditAssetID As Integer = 0
    Public EditEmpID As Integer = 0
    Public MisUser As Integer = 0
    Public BuyUser As Integer = 0
    Public ProfID As Integer = 0
    Public EditUserID As Integer = 0
    Public EditEmpBenID As Integer = 0
    Public EditPCPmainMember As String = ""
    Public EditPCPsubMember As String = ""
    Public trackBM_PO As String = "NIL"

    Public DepartmentID As Integer = 7
    Public PostingPC As String = "000"

    Public GlEmpID As Integer
    Public GlEmpName As String
    Public GlEmpDocNum As String

    Public GlEmpDocType As String
    Public GlEmpDocRefer As String

    Public GlArCusID As Integer
    Public GlArSMan As Integer
    Public GlArDocNum As String
    Public GlArDocType As String
    Public GlArDocRefer As String
    Public GlArCusName As String

    Public GlApSupID As Integer
    Public GlApDocNum As String
    Public GlApDocType As String
    Public GlApDocRefer As String
    Public GlApFc As String
    Public GlApFcAmt As String
    Public GlApSupName As String

    Public GlFaAssetID As Integer
    Public GlFaDocNum As String
    Public GlFaDocType As String
    Public GlFaDocRefer As String
    Public GlArFaName As String

    Public GVposTotal As Double
    Public ValidUser As Boolean
    Public RtnMfrCode As String
    Public RtnCusID As Integer
    Public CrCardNo As String = ""
    Public CrCardName As String = ""
    Public CrCardType As String = ""
    Public CrCardAuthNo As String = ""
    Public CrCardExp As String = Now.ToShortDateString
    Public PosCusName As String = ""
    Public PosCusID As Integer = 0
    Public SearchProductID As Integer = 0
    Public SearchProduct As String = ""
    Public SearchMfrCode As String = ""
    Public SearchedInvNo As String

    Public gstrWholesaleInvoiceNumber As String

    Public SearchedInvDesc As String
    Public SearchedInvQty As String
    Public SearchedInvPrice As String
    Public SearchedInvDisp As String
    Public SearchedInvDisa As String
    Public SearchedInvLtot As String
    Public SearchedInvShowroom As String
    Public SearchedInvDate As String
    Public PosCusReqID As Integer
    Public SearchBarCode As String = ""
    Public SearchInvNo As Integer
    Public delnote As Integer = 1
    Public SearchRtnNo As Integer
    Public SearchedRtnNo As String
    Public SearchWhTrfrNo As String
    Public SearchedWhTrfrNo As String
    Public SearchQtnNo As Integer
    Public SearchedQtnNo As String
    Public SearchLpoNo As Integer
    Public SearchedLpoNo As String
    Public SearchOrdNo As Integer
    Public SearchedOrdNo As String
    Public SearchShpNo As Integer
    Public SearchedShpNo As String
    Public MDRKey As String
    Public EngineCode As String
    Public SearchTrvNo As Integer
    Public SearchedTrvNo As String
    Public SearchPurhRtnNo As Integer
    Public SearchedPurhRtnNo As String
    Public SearchAdjNo As Integer
    Public SearchedAdjNo As String
    Public SearchCountNo As Integer
    Public SearchedCountNo As String
    Public SearchPricingNo As Integer
    Public SearchedPricingNo As String
    Public SearchEmailNo As Integer
    Public SearchedEmailNo As String
    Public SearchTrxNumber As String
    Public SearchRecurName As String
    Public MfrSample As String
    Public MfrDupe As String
    Public ItCode As String
    Public SearchGRVNumber As String

    Public ShowOnlySupplierProduct As Boolean
    Public CustomerID As Integer
    Public SupplierID As Integer
    Public EditBudID As Integer

    Public string1, string2, string3, RelatedProduct, ButtonSelected As String
    Public stwarr As String
    Public booSearch As Boolean = False
    Public booSearch1 As Boolean
    Public stproduct As String
    Public stWarrText, stWrCod, frm As String 'stCatName,
    Public iWarrMon, iWarrYr, iWarrCnt As Integer
    Public costvalid As Boolean
    Public btaddpress, bteditpress, btdeletepress As Boolean
    '''for invoice screen
    Public cusstring1, strCusName As String
    Public cusPopAct, CardPopAct, WarrPopAct, DetailAct As Boolean '
    Public stprod, stprodmain, stprodmain1, stprodmain2, btrelated As String
    Public btPriceFrom, InvDetailsFrom, TemDetailsFrom, DoDetailsFrom As String
    Public relrow, relrow3, seQty, iTemTot As Integer ''seQty to display Serial No ,   
    Public Crdname As String
    Public no, CRname, exMo, exYr, st, st3, stna As String
    Public tempinvNo, DOrderNo As String ''to populate TI and DO details
    Public ct, edt As String '''' Edited text in editwindow
    Public fromSR As String ''' salesreturn to invoicelist
    Public strInvID, strInvID3 As String
    Public no1 As Integer
    Public cvtText(30) As String
    Friend PrntPrv As PrintPreviewForm
    Public HuRekey() As Byte = {}
    Public DelGlTran As Boolean = True
    Public InvoicePrinter As String = ConfigurationManager.AppSettings("InvoicePrinter")
    Public InvoicePrintPath As String = ConfigurationManager.AppSettings("InvoicePrintPath")

    Public D_customer As String
    Public D_area As String
    Public D_block As String
    Public D_street As String
    Public D_jadha As String
    Public D_houseno As String
    Public D_telephone As String
    Public D_mobile As String
    Public D_location As String
    Public D_salesman As String
    Public D_invoice As String
    Public D_payment As String
    Public D_advance As String
    Public D_balance As String
    Public D_deliveryteam As String
    Public D_deliverydate As String
    Public D_remarks As String
    Public D_cmbShowroom As String



    Public Sub AutoCompleteCombo_KeyUp(ByVal cbo As ComboBox, ByVal e As KeyEventArgs)
        Dim sTypedText As String
        Dim iFoundIndex As Integer
        Dim oFoundItem As Object
        Dim sFoundText As String
        Dim sAppendText As String
        Select Case e.KeyCode
            Case Keys.Back, Keys.Left, Keys.Right, Keys.Up, Keys.Delete, Keys.Down
                Return
        End Select
        sTypedText = cbo.Text
        iFoundIndex = cbo.FindString(sTypedText)
        If iFoundIndex >= 0 Then
            oFoundItem = cbo.Items(iFoundIndex)
            sFoundText = cbo.GetItemText(oFoundItem)
            sAppendText = sFoundText.Substring(sTypedText.Length)
            cbo.Text = sTypedText & sAppendText
            cbo.SelectionStart = sTypedText.Length
            cbo.SelectionLength = sAppendText.Length
        End If
    End Sub
    Public Function IsNumericData(ByVal inputData As String) As Boolean
        inputData = inputData.Trim
        If Not IsDBNull(inputData) Then
            If inputData <> "" Then
                If Not IsNumeric(inputData) Then
                    Return False
                Else
                    Return True
                End If
            End If
        End If
    End Function
    Public Sub AutoCompleteCombo_Leave(ByVal cbo As ComboBox)
        Dim iFoundIndex As Integer
        iFoundIndex = cbo.FindStringExact(cbo.Text)
        cbo.SelectedIndex = iFoundIndex
    End Sub
    Public Function Q(ByVal SQLText As String) As String
        'the purpose of this function is to allow the user to insert single quotes in text boxes then into the database.
        If SQLText <> "" Then
            Q = (Replace(SQLText, "'", "''"))
        End If
    End Function
    Public Sub FormatDate(ByVal ct As TextBox, ByVal ea As System.Windows.Forms.KeyEventArgs)
        Dim i As Integer
        i = ct.SelectionStart
        If ea.KeyCode <> Keys.Back And ea.KeyCode <> Keys.Right And ea.KeyCode <> Keys.Left Then
            If i = 2 Then
                If ct.Text.IndexOf("/") <> 2 Then
                    ct.Text = ct.Text.Insert(2, "/")
                End If
                ct.SelectionStart = 3
            ElseIf i = 5 Then
                If ct.Text.LastIndexOf("/") <> 5 Then
                    ct.Text = ct.Text.Insert(5, "/")
                End If
                ct.SelectionStart = 6
            End If
        End If
    End Sub
    Public Function AmountToWords(ByVal strAmount As String, ByVal Cur As String) As String
        Dim x As Long
        Dim ConvertedText As String

        Dim dplace As Integer = strAmount.IndexOf(".")
        Dim decval As String = strAmount.Substring(dplace + 1, 3)
        x = Long.Parse(strAmount.Remove(dplace, strAmount.Length() - dplace))

        Dim t As Long

        cvtInit()

        If x > 999999999 Then
            ConvertedText = "" ' "Number to large"
            Exit Function
        End If

        If x > 999999 Then
            t = x \ 1000000
            ConvertedText = cvt100(t) & cvtText(30) & " "
            x = x - (t * 1000000)
        End If

        If x > 999 Then
            t = x \ 1000
            ConvertedText = ConvertedText & cvt100(t) & cvtText(29) & " "
            x = x - (t * 1000)
        End If

        If x > 0 Then
            ConvertedText = ConvertedText & cvt100(x)
        End If
        If decval <> "000" Then
            If Cur = "USD" Or Cur = "EUR" Or Cur = "SGD" Then
                ConvertedText = ConvertedText & " AND CENTS " & decval & "/1000 ONLY"
            ElseIf Cur = "GBP" Then
                ConvertedText = ConvertedText & " AND PENCE " & decval & "/1000 ONLY"
            Else
                ConvertedText = ConvertedText & " AND FILS " & decval & "/1000 ONLY"
            End If

        Else
            ConvertedText = ConvertedText & " ONLY"
        End If
        AmountToWords = ConvertedText.ToUpper
    End Function
    Private Sub cvtInit()
        cvtText(1) = "One"
        cvtText(2) = "Two"
        cvtText(3) = "Three"
        cvtText(4) = "Four"
        cvtText(5) = "Five"
        cvtText(6) = "Six"
        cvtText(7) = "Seven"
        cvtText(8) = "Eight"
        cvtText(9) = "Nine"
        cvtText(10) = "Ten"
        cvtText(11) = "Eleven"
        cvtText(12) = "Twelve"
        cvtText(13) = "Thirteen"
        cvtText(14) = "Fourteen"
        cvtText(15) = "Fifteen"
        cvtText(16) = "Sixteen"
        cvtText(17) = "Seventeen"
        cvtText(18) = "Eighteen"
        cvtText(19) = "Nineteen"
        cvtText(20) = "Twenty"
        cvtText(21) = "Thrity"
        cvtText(22) = "Forty"
        cvtText(23) = "Fifty"
        cvtText(24) = "Sixty"
        cvtText(25) = "Seventy"
        cvtText(26) = "Eigthty"
        cvtText(27) = "Ninety"
        cvtText(28) = "Hundred"
        cvtText(29) = "Thousand"
        cvtText(30) = "Million"
    End Sub

    Private Function cvt100(ByVal x As Integer)
        Dim t As Integer

        If x > 999 Then
            cvt100 = "" '"Error 100"
            Exit Function
        End If

        If x > 99 Then
            t = x \ 100
            cvt100 = cvtText(t) & " " & cvtText(28) & " "
            x = x - (t * 100)
        End If

        If x > 20 Then
            t = x \ 10
            cvt100 = cvt100 & cvtText(t + 18) & " "
            x = x - (t * 10)
        End If

        If x > 0 Then
            cvt100 = cvt100 & cvtText(x) & " "
        End If
    End Function

End Module
